﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TreeBuilder
{
	public class SnapshotAction : UndoableAction
	{
		private readonly IMenuChangeableObject _obj;
		private readonly Dictionary<string, object> _snapshot;
		private readonly Dictionary<string, object> _newState;

		public SnapshotAction(IMenuChangeableObject obj, Dictionary<string, object> snapshot, Dictionary<string, object> newState)
		{
			_obj = obj;
			_snapshot = snapshot;
			_newState = newState;
		}

		public override void Execute()
		{
			//For redo only, initially changes are done via ContextMenu bindings
			if (_obj.DetectChanges(_newState))
				_obj.RestoreSnapshop(_newState);
		}

		public override void Undo()
		{
			_obj.RestoreSnapshop(_snapshot);
		}
	}
}
